import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:syn_4s/core/extension/build_context_extension.dart';
import 'package:syn_4s/core/extension/int_extension.dart';

import '../../../core/model/short_model.dart';
import '../../../core/viewmodel/change_language_view_model.dart';
import '../../shared/app_theme.dart';
import '../../widgets/gradient_button.dart';
import '../../widgets/my_drop_down.dart';
import '../../widgets/shadow_container.dart';

class LanguageContent extends StatelessWidget {
  LanguageContent({super.key});

  final ChangeLanguageViewModel viewModel = Get.find<ChangeLanguageViewModel>();

  @override
  Widget build(BuildContext context) {
    return Container(
      height: double.infinity,
      decoration: const BoxDecoration(
        gradient: LinearGradient(
            colors: [AppTheme.bgStartColor, AppTheme.bgEndColor]),
      ),
      child: Column(
        children: [
          ShadowContainer(
            border: Border.all(color: AppTheme.orangeColor),
            margin: EdgeInsets.symmetric(horizontal: 12.px, vertical: 8.px),
            padding: EdgeInsets.only(
                left: 8.px, right: 8.px, top: 24.px, bottom: 56.px),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Text(
                  context.l10n.change_language,
                  style: const TextStyle(color: Colors.black),
                ),
                buildLanguage(context.l10n.language, viewModel.language),
                SizedBox(
                  height: 72.px,
                ),
                buildButton(context)
              ],
            ),
          ),
          const Spacer()
        ],
      ),
    );
  }

  Widget buildLanguage(String title, RxString content) {
    return MyDropDown(
      <ShortModel>[
        ShortModel(name: "中文", code: "1"),
        ShortModel(name: "English", code: "2"),
      ],
      content,
      margin: EdgeInsets.only(top: 24.px),
      padding: EdgeInsets.only(left: 12.px, right: 8.px),
      fontSize: 18.px,
      onSelected: (value) {
        viewModel.changeLanguageValue(value.code);
      },
      checkValue: ShortModel(name: "中文", code: "1"),
    );
  }

  Widget buildButton(BuildContext context) {
    return GradientButton(
        onPressed: () {
          viewModel.save(context);
        },
        child: Text(
          context.l10n.save,
          style: TextStyle(color: Colors.white, fontSize: 20.px),
        ));
  }
}
